package base.thread_JUC.demo01;

import java.util.concurrent.atomic.AtomicReference;

/**
 * 现实业务场景不仅仅原子整型的这么一种存在，原子User类型，原子Order类型都是存在的，因此 JUC提供了 AtomicReference<T>
 *
 * 原子引用类型演示
 */
public class Client6 {
    public static void main(String[] args) {
        Person zs = new Person("zs", 18);
        Person lisi = new Person("lisi", 19);

        /**
         * MYWHAT
         * AtomicReference使用场景?
         */
        AtomicReference<Person> atomicReference = new AtomicReference<>();
        atomicReference.set(zs);

        System.out.println(atomicReference.compareAndSet(zs, lisi)+ "\t " +atomicReference.get());
        System.out.println(atomicReference.compareAndSet(zs, lisi)+ "\t " +atomicReference.get());

    }

}

class Person{
    private String name;
    private Integer age;

    public Person(String name, Integer age){
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}
